package com.one.dao;

import com.one.entity.Server;
import com.one.entity.User;
import com.one.utils.DbConn;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

public class ServerDao {
    //增删改查的工具
    private QueryRunner runner = new QueryRunner(DbConn.getDataSource());

    /**
     * server服务的增加
     */
    public boolean addServer(Server server){
        Object[] params = {null,server.getHk_id(),server.getServer_type(),
                server.getServer_name(),server.getServer_price()};
        String sql = "insert into user values(?,?,?,?,?)";
        try {
            return runner.update(sql,params)>0;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * server服务的删除
     */
    public boolean delServer(int server_id){
        String sql = "delete from server where server_id=?";
        try {
            return runner.update(sql,server_id)>0;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     *  server服务的删除的修改
     */
    public boolean updServer(Server server){
        Object[] params = {server.getHk_id(),server.getServer_type(),
                server.getServer_name(),server.getServer_price(),server.getServer_id()};
        String sql = "update  server set hk_id=?,server_type=?," +
                "server_name=?,server_price where server_id=?";
        try {
            return runner.update(sql,params)>0;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }

}
